MGames MGames - 15 days ago 10
Javascript Question

JQuery- Input Value Isn't Changing?

I don't understand why the value isn't changing for this input from the website. I've tried this jquery code:

$('input[type=text].u').val('http://website/');


But it isn't changing or working:

https://jsfiddle.net/cq4e02yj/

Also I've tried to trigger click the button but that isn't working either.

-Thanks

Answer

Here's a first working solution. You are missing the quotes around type="text". Hope it helps.

$(document).ready(function() {

$("#myButton").click(function(){
	$('input[type="text"]').val('http://website/');

})
});
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<center><input name="u" id="input" size="60" class="textbox" value="http:/s/" type="text"><input value="Change My IP Address" id = "myButton" class="button" type="submit"></center>

Here's a second solution without clicking on button.

$('input[type="text"]').val('http://website/');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<center><input name="u" id="input" size="60" class="textbox" value="http:/s/" type="text"><input value="Change My IP Address" id = "myButton" class="button" type="submit"></center>