abadi
abadi

Reputation: 11

Javascript onclick action in button with two functions

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 ?

Upvotes: 0

Views: 468

Answers (3)

Mohit Pandey
Mohit Pandey

Reputation: 3813

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'" >

Upvotes: 0

Jad Joubran
Jad Joubran

Reputation: 2579

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';
}

Upvotes: 0

Miltos Kokkonidis
Miltos Kokkonidis

Reputation: 3996

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/

Upvotes: 1

Related Questions