Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic