• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call Action from javascript

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!
i would like some help with what i am trying to do.i am making my project using struts and jsp.in my jsp for user registering,i use validation.xml for checking that user inputs corrrect data.but i am trying to write a javascript function which checks if user has selected the same values in more than one of the 3 selects i have in the page.if that is the case i would like a message to appear and let the user change his choice.unfortunately i cannnot do that
the problem is that the Action takes control and the user doesnt have the chance to change his input...any ideas ???thanks!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You using onsubmit?



Eric
 
natasa jones
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my code is

<script type="text/javascript">
function checkUniquePrefs() {

var test = document.getElementById("myform")

var list = document.getElementById("select1")
var name = list.options[list.selectedIndex].text

var list2 = document.getElementById("select2")
var name2 = list2.options[list2.selectedIndex].text
var list3 = document.getElementById("select3")
var name3 = list3.options[list3.selectedIndex].text


if (name != name2 && name != name3 && name2 != name3) {
test.submit();

} else {
alert("alert");
}

}
</script>

what is wrong with that code?
 
natasa jones
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have tried it using onsubmit and also on click but in neither cases does this work..any thoughts?thanks!
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are uswing onsubmit than you need to return true or false

if (name != name2 && name != name3 && name2 != name3) {
return true;

} else {
alert("alert");
return false;
}
 
natasa jones
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this function is driving me crazy!
it does submit even though i return false in case of mistake!!!
the Action takes the control and i can figure out why!!!
i have tested calling the function from an input type of submit,from a simple button and from the form onsubmit but it never works!it always submits!!!why?any thoughts??thanks!
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it does not work, than you have a JavaScript error in your code:

Basic working code here:


Eric
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you put entire code here ..I will try to submit to my struts action.

the code you gave works for me ...but I am submitting to http://www.javaranch.com rather than a struts action. And when it run across error it DOES NOT submit...
 
natasa jones
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i cant believe my eyes!!it works!!!finally!thank you soooo much!
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic