Jump to content

Checkbox value in javascript


Recommended Posts

Hello,

I have a checkbox in a detail page.

I want to use the checkbox value in a script in the footer of that page.

The problem is that it is always giving me the checked value even when not checked.

Here is my script:

<script>
document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){
var dropdown = document.getElementById('cbParamVirtual4').value;
var vendu = document.getElementById('EditRecordOKpourVendu').value;
if (vendu == "Y") {dropdown = "7"; }
document.getElementById('EditRecordstage_id').value = dropdown;
};
</script>

I have no problem to get the Virtual4 value, it is a dropdown menu.

Thanks for your help

Link to comment
Share on other sites

Hello @ChrisV,

It looks like the Yes/No field always has the "Y" value even when the checkbox is not checked:

y7PvIC9.png

 

Please try to check the 'checked' attribute instead. If 'checked' is equal to 'true', then checkbox is checked. 

<script>
document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){
var dropdown = document.getElementById('cbParamVirtual4').value;
var vendu = document.getElementById('EditRecordOKpourVendu');
if (vendu.checked === true) {dropdown = "7"; }
document.getElementById('EditRecordstage_id').value = dropdown;
};
</script>

Hope this helps.

Link to comment
Share on other sites

Hello @CoopperBackpack ,

Thanks for your reply and for leading me in the right way, this helped a lot.
I had to make it a little bit different to make it works.

Here is the working solution:

<script>
document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){
var dropdown = document.getElementById('cbParamVirtual4').value;
if (document.getElementById('EditRecordOKpourVendu').checked == true) {dropdown = "7"; }
document.getElementById('EditRecordstage_id').value = dropdown;
};
</script>

Thanks and best regards

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...