0

Why this script cannot send the value in the button with onclick action simple javascript

<input type="submit" onclick="(document.getElementById('act').value='delete_user')&&(document.getElementById('uid').value='1')" >

But this script worked

<input type="submit" onclick="(document.getElementById('act').value='delete_user')>

How make both values get work ?

3
  • does "(document.getElementById('uid').value='1')" also work on its own? incidentally aren't you missing a " just before > in the example you say worked? Commented Dec 2, 2012 at 14:16
  • Updated my answer. Please try the jsFiddle provided. Commented Dec 2, 2012 at 14:29
  • Remove brackets in onclick section. it should work Commented Dec 3, 2012 at 11:30

3 Answers 3

1

This should work:

<input type="submit" onclick="document.getElementById('act').value='delete_user';document.getElementById('uid').value='1'; " >

If it does not, please check if there is an input with id (not name) uid and that the following also works.

<input type="submit" onclick="document.getElementById('uid').value='1'; " >

Check it out here:

http://jsfiddle.net/r7tuT/3/

Sign up to request clarification or add additional context in comments.

Comments

0

Use this in the html <input type="submit" onclick="my_function();">

and add in the javascript part:

function my_function(){
    document.getElementById('act').value='delete_user';
    document.getElementById('uid').value='1';
}

1 Comment

True,but I believe this should also work <input type="submit" onclick="my_function1();my_function2();"> if he wants to call two functions when submit is clicked.
0

You are using &&, which is used for validation purpose.

Correct code is :

<input type="submit" onclick="document.getElementById('act').value='delete_user';document.getElementById('uid').value='1'" >

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.