/    Sign up×
Community /Pin to ProfileBookmark

CHECKBOX/ JavaScript emergency problem. What’s wrong??

I have a problem with two checkboxes .

I need to change value of the output depending on if one or two checkboxes were checked.

Please take a look at the code and tell me what needs to be between the {} in Java Script. THANK YOU!!

[COLOR=”DarkRed”]

<head>
<SCRIPT TYPE=”text/javascript” LANGUAGE=JAVASCRIPT>

function checkCheckBoxes() {
if (document.form1.selectedProd.checked == true && document.form1.selectedProd2.checked == true)
{
[COLOR=”Red”]I need to put something here that sends to the server
slectedProd as a “name” and value=”u3″. And this is the only thing that should be send. slectedProd2 should not be sent. [/COLOR]

}
}
//–>

</head>

<body>

<form name=”form1″ method=”POST”>
<input type=”checkbox” id=”N1″ name=”selectedProd” value=”u”>1</p>
<input type=”checkbox” id=”N2″ name=”selectedProd2″ value=”u2″>2</p>
<input type=”submit” value=”Submit” name=”submit” onclick=”checkCheckBoxes();” />

</form>
</body>
</html>[/COLOR]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMay 06.2009 — Something like this what you want?:
[code=html]<head>
<script type="text/javascript">

function checkCheckBoxes() {
var elem1 = document.form1.selectedProd,
elem2 = document.form1.selectedProd2;
if (elem1.checked && elem2.checked) {
elem1.value = 'u3';
elem2.value = '';
return true;
}
//change the below to true and remove the above return statement
//if you want to still submit with only one checked
return false;
}

</script>
</head>

<body>

<form name="form1" method="post" action="page2.php">
<input type="checkbox" id="N1" name="selectedProd" value="u">1</p>
<input type="checkbox" id="N2" name="selectedProd2" value="u2">2</p>
<input type="submit" value="Submit" name="submit" onclick="return checkCheckBoxes();" />
</form>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@kamil607authorMay 06.2009 — This is exactly what I need. I did not know you can change value that easily. Now I have to test it with my form. Thanks Again !!! ?
×

Success!

Help @kamil607 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...