Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Set Selection Box value as variable

Featured Replies

Hi all,

What I'm trying to do is set the value of the user-selection from the box as a global variable that I can use outside of the function.

I think the code below should work but it doesn't.... any ideas?

 

<script>
var c1;
   function countryfunc(val) {
       c1=val;
   }
document.getElementById('output').innerHTML = c1;
</script>

<div id="output"></div>

<select name="select" id="select" onchange="countryfunc(this.value);">
       <option value="16">Spain</option>
       <option value="15">Germany</option>
       <option value="14">Netherlands</option>
       <option value="13">Portugal</option>
</select>

 

Thanks a lot in advance!

Edited by nuksies

  • 2 weeks later...

In the first place stop spam the forum, just wait for an answer!

 

I will give you an example

<select id="leaveCode" name="leaveCode">
 <option value="10">Annual Leave</option>
 <option value="11">Medical Leave</option>
 <option value="14">Long Service</option>
 <option value="17">Leave Without Pay</option>
</select>

 

You can use this JS:

 

function setSelectValue (id, val) {
   document.getElementById(id).value = val;
}
setSelectValue('leaveCode', 14);

 

 

Cheers B)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.