0

Im developing chrome extension. I want to change input value(username) to some text when user click button. But my solution not working. Need advise. My code is shown below:

<!DOCTYPE html>
<html>
<head>  
<META http-equiv=content-type content=text/html;charset=utf8>
<META http-equiv=content-type content=text/html;charset=windows-1254>
<META http-equiv=content-type content=text/html;charset=x-mac-turkish>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>  
<title></title>
<script>
    $('#target').submit(function() {
    alert('something');
    return false;
    $('#UserName').value('test');
});
</script>
</head>
<body>
<form id="target">
<table>
  <tr>
    <td>UserName:</td>
    <td>
      <input type="text" id="UserName" size="20" />
    </td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>
      <input type="password" id="Password" />
    </td>
  </tr>
  <tr>
    <td></td>
<td><input type="button" value="Login" id="Login" /></td>
  </tr>
</table>
</form>
</body>
</html>

5 Answers 5

2

Change your submit button from type button to submit from:

 <input type="button" value="Giriş" id="Login" /> 

to:

<input type="submit" value="Giriş" id="Login" />

Also change your JS code from:

$('#target').submit(function() {
alert('uyarı');
return false;
$('#UserName').value('deneme');

to:

$('#target').submit(function() {
 alert('uyarı');    
 $('#UserName').val('deneme');
 return false;
Sign up to request clarification or add additional context in comments.

1 Comment

Tried but nothing changed except form refreshing.
2

Your submit button needs to be of type 'submit'.

So this:

<input type="button" value="Login" id="Login" />

should be:

<input type="submit" value="Login" id="Login" />

Also, the appropriate jQuery function for getting/setting input values is .val().

Lastly, you don't want to return false until the end of the function.

$('#target').submit(function() {
    alert('something');      
    $('#UserName').val('test');
    return false;
});

See this working Fiddle.

3 Comments

I looked in fidlle. Yes it works. But In my extension it doesnt work.
Are you getting any JavaScript errors in your console? The above could is the correct way to complete the tasks you specified using jQuery.
I am developing chrome extension. When i open my html in browser all is fine and works. But when i install my extension into chrome nothing works. I clicked button to many times but it is refreshing page only there is no alert no error.
1

This is working fine

$('input#Login').click(function() {        
    $('#UserName').val('test');
    return false;
});

Comments

1

jQuery uses the VAL rather than VALUE

in other words

<script>
    $('#target').submit(function() {
    alert('something');
    return false;
    $('#UserName').val('test');
});
</script>

and also the FORM is not submitado change the type of input and submit to the adciona FORM METHOD = "POST"

3 Comments

Thanks for answer but still nothing changed
@pale changed the response of a look
I am developing chrome extension. When i open my html in browser all is fine and works. But when i install my extension into chrome nothing works. I clicked button to many times but it is refreshing page only there is no alert no error. But when open in browser everythings works fine.
0

Guys thank you very much. I found. The problem is when you are developing google chrome application you must seperate javascript code from html. Otherwise javascript not work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.