Win a copy of Functional Design and Architecture this week in the Functional programming 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Pre select a dropdown using cookie.

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there!

I am trying to use cookie to compare to a dropdown and preselect the dropdown upon a match.

Here is what I am trying so far...


This doesn't even persist the dropdown selection in the same session. I don't see the pop-ups (alert and prompt) neither. And same when I log back in, it won't show my previous selection (in my last session) .

What is the right way to achieve this!

thanks a lot!
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where's your preselect thing getting called? is it using: ?
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trilochan Bharadwaj wrote:where's your preselect thing getting called? is it using: ?



Hi Trilochan,

I re-examined my code, and made changes. You are right. I am using onload, here is my code:



I get error on line 96,


line 60,


I am not able to get the "dropdown option" selected by the user and also "all the items in the dropdown"
 
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 are never calling the code to set the cookie value.

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:You are never calling the code to set the cookie value.

Eric



Hi,
I made the corrections. Now I am getting undefined value (value for g in the code below), when I try to get the user selection from the dropdown. I am setting value of g in line 28.


I also get null error while getting the dropdown list (line 29, dl) to loop through and compare the cookie value.

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
not sure why you would be using this there. This scope would be the window and not the form.

document.formName.elementName
or
document.getElementById("elementId")

would be the correct way to access a form element.

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:not sure why you would be using this there. This scope would be the window and not the form.

document.formName.elementName
or
document.getElementById("elementId")

would be the correct way to access a form element.

Eric



I followed your code and had it working. But the code is only getting executed when the screen gets loaded (all my code is in window.onload). The form has a button (along with dropdown). In the onSubmit I again have to call setCookie with the new user selection (in dropdown).

How to call javascript inside form element ?

Thanks a lot!
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'd use attachEventListener personally.

Trilochan.
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trilochan Bharadwaj wrote:
I'd use attachEventListener personally.

Trilochan.



I didn't get your point. My form code is like this.


The code for button (go) is on line 9. How to relate function "setCookie" with the button. I have to associate 2 things with the onSubmit, one is to call an application which I am doing in the line 3, the second one is to call a javascript function "setCookie". Is it possible to associate two actions with onSubmit.

Thanks
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah i c ... so do you want those things to be invoked in order?

well this is off the bat, but you'd do this:


Hope this helps!
Trilochan
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried both options. Somehow, I am not able to associate setCookie with "onSubmit" button of the form. Is this because, I am going to a different page upon onSubmit click ?

As a result, the cookie is never set. Can you give me sample code as to how to write a javascript function inside form element.

 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you have onsubmit connected to something that is being called on server side, for the form, use onclick for the button and not onsubmit.
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
paste the code you're trying at the moment, I'll sift through it once I get out of the office ... I hope you're not in a rush.

Trilochan.
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it, I referred this link

Thanks a lot for your patience!
Resolved!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic