Jump to content
UBot Underground

[Free Code] Selected Dropdown Menu Item To Execute A Define


Recommended Posts

Here's a sample code on how to execute a define when a certain menu item is selected.

 

Download dropdownMenuExecute.ubot

 

What can you do with this?

- Load additional options when certain item is selected

- For selecting profile settings. Fill the UI forms when certain profile is selected

- Automatically check the requirements if the user is eligible to select the item. If not alert them to select different item

- etc...

 

Enjoy..

  • Like 3
Link to post
Share on other sites

Hi Kreatus,

 

I had done the same thing but you need to be aware that there is one problem using that method with a dropdown. Using the example code you supplied, if a user selects 4 then the command will run, but the problem is if they click on the dropdown again but decide to click on the option that is already selected(in this case 4) then nothing will happen, until the next time they click on the dropdown. Then the next time they click on the dropdown, the command that is assigned to run when(in this case 4) is selected will run immediately before they make any other selection. Hope that makes sense.

 

It's for that reason I think it's better to use a listbox to achieve the same result. The method works flawlessly with a listbox.

 

Cheers.

 

[Edit] To use this method with a listbox the code below is all thats required:

ui html panel("<span onclick=\"ubot.runScript(\'test()\')\"><select size=\"5\" variable=\"#dropDownVar\" fillwith=\"value\" name=\"dropdown\" style=\"width:\">
  <option value=\"0\">0</option>
  <option value=\"1\">1</option>
  <option value=\"2\">2</option>
  <option value=\"3\">3</option>
  <option value=\"4\">4</option>
  <option value=\"5\">5</option>
  <option value=\"6\">6</option>
  <option value=\"7\">7</option>
  <option value=\"8\">8</option>
  <option value=\"9\">9</option>
  <option value=\"10\">10</option>
</select>
</span>
<span variable=\"#otherOptions\" fillwth=\"innerhtml\"></span><span variable=\"#selectedMenu\" fillwith=\"innerhtml\"></span>", 100)
define test {
    if($comparison(#dropDownVar, "=", 4)) {
        then {
            alert("Execute something!")
        }
        else {
        }
    }
}
  • Like 1
Link to post
Share on other sites

 

Hi Kreatus,

 

I had done the same thing but you need to be aware that there is one problem using that method with a dropdown. Using the example code you supplied, if a user selects 4 then the command will run, but the problem is if they click on the dropdown again but decide to click on the option that is already selected(in this case 4) then nothing will happen, until the next time they click on the dropdown. Then the next time they click on the dropdown, the command that is assigned to run when(in this case 4) is selected will run immediately before they make any other selection. Hope that makes sense.

 

It's for that reason I think it's better to use a listbox to achieve the same result. The method works flawlessly with a listbox.

 

Cheers.

 

[Edit] To use this method with a listbox the code below is all thats required:

ui html panel("<span onclick=\"ubot.runScript(\'test()\')\"><select size=\"5\" variable=\"#dropDownVar\" fillwith=\"value\" name=\"dropdown\" style=\"width:\">
  <option value=\"0\">0</option>
  <option value=\"1\">1</option>
  <option value=\"2\">2</option>
  <option value=\"3\">3</option>
  <option value=\"4\">4</option>
  <option value=\"5\">5</option>
  <option value=\"6\">6</option>
  <option value=\"7\">7</option>
  <option value=\"8\">8</option>
  <option value=\"9\">9</option>
  <option value=\"10\">10</option>
</select>
</span>
<span variable=\"#otherOptions\" fillwth=\"innerhtml\"></span><span variable=\"#selectedMenu\" fillwith=\"innerhtml\"></span>", 100)
define test {
    if($comparison(#dropDownVar, "=", 4)) {
        then {
            alert("Execute something!")
        }
        else {
        }
    }
}

 

Thanks for the suggestion darryl. I added your code the the source.

 

I made a little workaround to notify the user to wait when they execute something that will take a little while.

It's not perfect but it will let them know not to click the dropdown when it's executing something..

 

dropdownMenuExecute.ubot

 

dropdownMenuExecute.ubot

Link to post
Share on other sites
  • 2 years later...

 

Hi Kreatus,

 

I had done the same thing but you need to be aware that there is one problem using that method with a dropdown. Using the example code you supplied, if a user selects 4 then the command will run, but the problem is if they click on the dropdown again but decide to click on the option that is already selected(in this case 4) then nothing will happen, until the next time they click on the dropdown. Then the next time they click on the dropdown, the command that is assigned to run when(in this case 4) is selected will run immediately before they make any other selection. Hope that makes sense.

 

It's for that reason I think it's better to use a listbox to achieve the same result. The method works flawlessly with a listbox.

 

Cheers.

 

[Edit] To use this method with a listbox the code below is all thats required:

ui html panel("<span onclick=\"ubot.runScript(\'test()\')\"><select size=\"5\" variable=\"#dropDownVar\" fillwith=\"value\" name=\"dropdown\" style=\"width:\">
  <option value=\"0\">0</option>
  <option value=\"1\">1</option>
  <option value=\"2\">2</option>
  <option value=\"3\">3</option>
  <option value=\"4\">4</option>
  <option value=\"5\">5</option>
  <option value=\"6\">6</option>
  <option value=\"7\">7</option>
  <option value=\"8\">8</option>
  <option value=\"9\">9</option>
  <option value=\"10\">10</option>
</select>
</span>
<span variable=\"#otherOptions\" fillwth=\"innerhtml\"></span><span variable=\"#selectedMenu\" fillwith=\"innerhtml\"></span>", 100)
define test {
    if($comparison(#dropDownVar, "=", 4)) {
        then {
            alert("Execute something!")
        }
        else {
        }
    }
}

could you help to show the code for checkbox and dropdown as the code above in html,thanks!

Link to post
Share on other sites

could you help to show the code for checkbox and dropdown as the code above in html,thanks!

 

Changed the dropdown to run a define "onchange" rather than "onclick"

ui html panel("<select onchange=\"ubot.runScript(\'test()\')\" variable=\"#dropDownVar\" fillwith=\"value\" style=\"width:60px;height:30px;border-radius:4px;\">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<br>
<br>
<input type=\"checkbox\" variable=\"#male\" fillwith=\"checked\">male
<br>
<input type=\"checkbox\" variable=\"#female\" fillwith=\"checked\">female",200)
define test {
    if($comparison(#dropDownVar,"=",4)) {
        then {
            alert("Execute something!")
        }
        else {
            alert(#dropDownVar)
        }
    }
}
Link to post
Share on other sites

 

Changed the dropdown to run a define "onchange" rather than "onclick"

ui html panel("<select onchange=\"ubot.runScript(\'test()\')\" variable=\"#dropDownVar\" fillwith=\"value\" style=\"width:60px;height:30px;border-radius:4px;\">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<br>
<br>
<input type=\"checkbox\" variable=\"#male\" fillwith=\"checked\">male
<br>
<input type=\"checkbox\" variable=\"#female\" fillwith=\"checked\">female",200)
define test {
    if($comparison(#dropDownVar,"=",4)) {
        then {
            alert("Execute something!")
        }
        else {
            alert(#dropDownVar)
        }
    }
}

thanks for your info..

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...