SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 28
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing values through URL

    Hello:

    I have a text field on my page. The user needs to be able to type in some value. I then need to pass this value through an a href link to another page in a new window. This is not a submit, but just through the a href url.
    Can anyone help me?

    Here is what I am doing so far, but now need to replace where it says serial=serial with the value the user just typed in.
    I heard something about using .value, but how do I add that using JS without using a function?
    Dan

    <a href="/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&serial=serial&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name# onclick="check_serial()"> "
    target="ur_window">

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you trying to do it without a function?

    I would use a function and here is what I would do. I am unsure of your syntax as I don't do cold fusion but you will get the drift:

    <head>
    <script language="javascript">
    function nextPage() {
    var sLocation;

    //i don't know what this does but i see you have
    //an onClick event for it. lets fire it first
    check_serial();

    //next we'll build our querystring and change pages
    sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&serial=" + frmYourFormName.taYourTextArea.value + "&whateverelse=whateverelse";

    //not sure of this line, might need to cut out 'document.'
    document.ur_window.location = sLocation;
    }
    </script>
    </head>
    <body>
    <a href="#" onClick="nextPage()">your link</a>
    </body>


    To get the value of your textarea, use the DOM to reference it and build it into your querystring.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok let me see if this helps you some.

    the following JS I am using to get the serial number value from the text fields onClick:

    <script>
    //
    var num= #form.weapon_count#;
    function check_serial(){
    for (i=1;i<num+1;i++){
    //"curr = document.receipt.NumericAlts"+i+".value"
    serial=eval("document.receipt.maj_asm_serial_nbr"+i+".value")
    alert(serial)
    var serial_nbr = serial;
    alert(serial_nbr)
    }
    }


    </script>

    now I am trying to use the ahref to pass that value. if I use the serial_nbr var from this and then add your sLocation code after defining the var, then replace my ahref with this: <a href="#" onClick="nextPage()">your link</a>
    would that do what I want it to do?

    maybe that was confussing...if so please tell me what does not make sense and I will clarify.

    Thanks

    dan

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think i get it. i would do this:

    <a href="#" onClick="check_serial()">

    lets just call your function. then, lets add our window.frame.location code to your function:

    function check_serial() {

    //declare your variables
    var sLocation;
    var serial;
    var serial_nbr;

    //all of your code goes here as i assume that its doing what you want it to do
    for (i=1;i<num+1;i++){
    //"curr = document.receipt.NumericAlts"+i+".value"

    serial=eval("document.receipt.maj_asm_serial_nbr"+i+".value")
    alert(serial)
    serial_nbr = serial;
    alert(serial_nbr)
    }



    //now lets add this
    sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&serial=" + serial + "&whateverelse=whateverelse";

    //not sure of this line, might need to cut out 'document.' or change 'document.' to 'window.' or vice versa
    window.ur_window.location = sLocation;


    }
    Last edited by makeda; Mar 27, 2002 at 15:18.

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line is the problem:

    window.ur_window.location = sLocation;

    when I click on the href link, a JS error pops up saying ur_window is undefined.

    This error keeps the link from finding the right page to open up in a new window...what is the code trying to do since ur_window is not defined anywhere.

    dan

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one other thing, in this line:
    <a href="#" onClick="check_serial()">

    i get an error "#" this part. it is a cold fusion error which you may not know but what is this doing for us?

    thanks

    dan

  7. #7
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    o.k., for the href error, try this instead:

    <a href="javascript:check_serial()">

    as for the ur_window error. i assumed that you were using frames and that you had a frame named 'ur_window'. if you are not using frames and you just want the whole window to change, use this instead:

    document.location = sLocation;

    if you want to open the page in a new window, try this:

    window.open(sLocation);

    We are referring to 'ur_window' through the DOM but if it can't find it, it will give us an error.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need a function to send Querystring values

    http://www.site.com/page.html?value1...lue2=something etc...


    But you'll need a function to receive the values,

    see: http://sitepointforums.com/showthrea...threadid=54193

  9. #9
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Flyswatter,

    You are correct if you know the values ahead of time. In this instance, we don't. Is it possible to dynamically build the link without a function? That is the problem we are grappling with.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose not, However the DOM should allow you to change the href value, then again if your willing to rely on JS, you might aswell use document.write to write the tags in.

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so I can pass serial numbers...Yeah!!!
    But my next issue with this code is this:
    i said that I had a text field...well what if I have more than one text field with the same name but with a loopcounter variable which increments the text field by one.
    example
    serial1
    serial2
    serial3...

    so the JS will pass only the last serial value every time. the following is my code. I think I need to do something to relate the href link and the loopcounter variable (in JS it is i). take a look and see if you see something that may help.

    <script>
    //
    var num= #form.weapon_count#;
    function check_serial(){
    for (i=1;i<num+1;i++){
    //"curr = document.receipt.NumericAlts"+i+".value"
    maj_asm_serial_nbr=eval("document.receipt.maj_asm_serial_nbr"+i+".value")
    alert(maj_asm_serial_nbr)
    //var serial_nbr = serial;
    //alert(serial_nbr)
    }
    var sLocation;
    sLocation = sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&maj_asm_serial_nbr=" + maj_asm_serial_nbr + "&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name#";
    //window.location = sLocation;
    window.open(sLocation);
    }


    </script>
    <!--- this is the issue...how do I figure out what is what with the link? --->
    <a href="javascript:check_serial()"> Generate UR#loopcounter#</a> &nbsp;&nbsp;




    Thanks

    Dan

  12. #12
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i was kind of wondering about that loop. i assumed it did what you wanted it to do, but obviously you are overwriting your values with each loop.

    so, do you want to pass the values for each textbox, everytime or do you want to pass the value for a given textbox depending on which link they click?

  13. #13
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so, do you want to pass the values for each textbox, everytime or do you want to pass the value for a given textbox depending on which link they click?

    to answer this, I need to pass whichever textbox value is associated to that particular link.

    the whole page is created in a loop. the links and textboxes are created depending on how many the user needs.
    so there could be only one textbox and link or there could be up to 100.

    hope this helps explain what is going on. My first thought was to create an array and add all the values into the array and pull out the value depending on which link you selected because that linke would have a loopcounter variable associated to it. Not sure if I am on the right track or if there is an easier way.

    Thanks
    Dan

  14. #14
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when you say the the links and textboxes are created using a loop, are you doing this server side? if so, add a parameter to the function and add an attribute to each <a> tag.


    The easiest attribute to add to the <a> tag would be the id for its corresponding text box ex.

    <a id="aLink1" href="javascript: check_serial(this)" textBoxRef="txt1">link 1</a>

    <input type="text" id="txt1" value="" />



    <a id="aLink2" href="javascript: check_serial(this)" textBoxRef="txt2">link 2</a>

    <input type="text" id="txt2" value="" />


    you get the idea of whats going on...when you build the ID for the textbox, set an attribute on your <a> tag equal to the same thing.

    Then in you function, add a parameter to the interface to tell it we are passing a reference to our <a> object

    function check_fields(refATag) {
    ...all of your code
    }

    then, you would probably replace the loop in your function with something like this:

    var serial = document.all(refATag.textBoxRef).value;

    this will get the value of the corresponding textbox

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not totally sure what you are doing. it looks like you are creating static links? my links are within the loop so they get created within a loop dynamically. let me give you pieces of code from the loop tag and include the js code:

    --setting the loop properties. form.weapon_count is the amount of weapons you are looping through--
    <cfset loopcounter = "1">
    <cfloop CONDITION="#loopcounter# LESS THAN OR EQUAL TO #form.weapon_count#">

    --the code I am using to try to pass the serial_nbr--
    <script>
    //
    var num= #form.weapon_count#;
    var part_number= #SpanExcluding(form.maj_asm_part_nbr, "-")#;

    function check_serial(){
    for (i=1;i<num+1;i++){
    //"curr = document.receipt.NumericAlts"+i+".value"
    maj_asm_serial_nbr=eval("document.receipt.maj_asm_serial_nbr"+i+".value")
    //alert(maj_asm_serial_nbr)
    //var serial_nbr = serial;
    //alert(serial_nbr)
    }
    //alert(part_number)
    part_nbr = eval("document.receipt.maj_asm_part_nbr.value")
    //alert(part_nbr)
    maj_nbr = (part_number+"-")
    //alert(maj_nbr)
    maj_part_nbr =(part_number+"-"+part_nbr)
    //alert(maj_part_nbr)
    var sLocation;
    sLocation = sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&maj_asm_part_nbr="+ maj_part_nbr +"&maj_asm_serial_nbr=" + maj_asm_serial_nbr +"&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name#";
    //window.location = sLocation;
    window.open(sLocation);
    }


    </script>

    --the href link with a loopcounter used to give it a 1,2,3,ect--
    <a href="javascript:check_serial()"> Generate UR#loopcounter#</a> &nbsp;&nbsp;

    --this is the actual text field. the loopcounter is used to create a field: name1, name2, ect.
    <input type="text" name="maj_asm_serial_nbr#loopcounter#" size="9" maxlength="9" value="#evaluate(temp)#"></td>

    --these fields will be created as many times as the loop condition is true. --
    --will end loop with an end loop tag.

    so my stuff is created dynamically and I am not sure if the code you just posted was actually like that or not?
    Hope this explains what I am trying to do

    dan

  16. #16
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, exactly. my examples are hardcoded so you can see whats going on but it is designed to work dynamically. i don't know cold fusion so you'll have to read between the lines.

    so where you are doing this:

    <input type="text" name="maj_asm_serial_nbr#loopcounter#" size="9" maxlength="9" value="#evaluate(temp)#"></td>

    you should now also do this:

    <a href="javascript:check_serial(this)" id="DYNAMICALLY BUILD A UNIQUE ID FOR EACH OF THESE" refTextBox="maj_asm_serial_nbr#loopcounter#"> Generate UR#loopcounter#</a>


    So now as you dynamically build each textbox/link pair, we are stashing the name of the link's corresponding textbox as an attribute on the <a> tag. See what I'm doing here?

    Now, each time somebody clicks a link, we pass it a reference to the specific link that is being clicked, which consequently has the name of the textbox that we want to access stored as an attribute.

    If what you are trying to do is change locations while passing the contents of the textbox which corresponds to the link that you just clicked, your function should look something like this:

    function check_fields(refATag) {
    var serial;

    //this gets the contents of the textbox
    //that corresponds to the link
    serial = document.all(refATag.refTextBox).value;

    //now add your code that builds the path to the page you want to link to



    }
    Last edited by makeda; Mar 28, 2002 at 14:42.

  17. #17
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is almost perfect. I thought you were just showing me what to do. Now as you can see I commented out the for loop and the eval line and left in the line you said to use and then added an alert. the alert shows me undefined serial number. I am trying to figure out why, but thought you may see something quicker than me.
    what ya think?

    <script>
    function check_serial(refATag){
    //for (i=1;i<num+1;i++){
    //maj_asm_serial_nbr=eval("document.receipt.maj_asm_serial_nbr"+i+".value")

    var maj_asm_serial_nbr = document.all(refATag.refTextBox).value;
    alert(maj_asm_serial_nbr)

    //}
    var sLocation;
    sLocation = sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&maj_asm_part_nbr="+ maj_part_nbr +"&maj_asm_serial_nbr=" + maj_asm_serial_nbr +"&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name#";
    //window.location = sLocation;
    window.open(sLocation);
    }


    </script>

    --added reftextbox= name with loopcounter and the id used the loopcounter variable to increment each link--
    <a id="#loopcounter#" href="javascript:check_serial(this)" refTextBox="maj_asm_serial_nbr#loopcounter#"> Generate UR#loopcounter#</a> &nbsp;&nbsp;

    --added id with name and loopcounter to match the reftextbox in the ahref link--

    <input type="text" name="maj_asm_serial_nbr#loopcounter#" id="maj_asm_serial_nbr#loopcounter#" size="9" maxlength="9" value="#evaluate(temp)#">

    I know I am real close.
    dan

  18. #18
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hhmmmm...really? i'm testing it here and its working. i'm guessing there might be a mis-spelling or something?

    I definitely see a problem with this:

    sLocation = sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&maj_asm_part_nbr="+ maj_part_nbr +"&maj_asm_serial_nbr=" + maj_asm_serial_nbr +"&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name#";


    change it to this so that you only have one 'sLocation=':

    sLocation = "/docs/ur/urblankform1.cfm?maj_asm_name=#form.maj_asm_name#&maj_asm_part_nbr="+ maj_part_nbr +"&maj_asm_serial_nbr=" + maj_asm_serial_nbr +"&mb_operation=receipt_new&discovery_event=RECEIPT&report_cat_code=WEAPON&mbunit_problem_summary=UR+generated+from+Receipt+of+#form.maj_asm_name#";

    The only other thing that I can think of is splitting this:

    var maj_asm_serial_nbr = document.all(refATag.refTextBox).value;


    into this:

    var sHolder;
    var maj_asm_serial_nbr;

    sHolder = refATag.refTextBox;
    maj_asm_serial_nbr = document.all(sHolder).value;

    Also, just as a test, check your alert box to see if you are getting the reference passed correctly:

    alert(refATag.id);

    That should display the ID for your <a> tag, see if this is working.

  19. #19
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man I can't believe it is working on your end...you are not getting an undefined for the refATag.id or the maj_asm_serial_nbr?
    Crap...
    Well I am heading to the families for the weekend so I will not be around to figure this out tomorrow.
    I will take a look for misspellings on monday and pass along another posting if I cannot solove it.
    Hope my next post is that I solved it but if not hope you can bare with me and this problem.

    Thanks and happy easter

    Dan

  20. #20
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats cool that you're getting an error for both, it tells us that the reference isn't being passed correctly. make sure the the reference you're using in your interface is the same that you're using in your function. example:

    this is correct:

    function whatever(refReference) {
    var test = refReference.value;
    }


    this is NOT correct:

    function whatever(refReference) {
    var test = referenceRef.value;
    }


    See what I'm saying...double check that you're not doing this by mistake.

  21. #21
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I remember correctly, you can't run this locally, you need to run this on the WEB, or a PWS.

  22. #22
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Happy Monday:
    Well I read your note about checking the function and other similarities, and if I understand your answer, I think things are the same:

    function check_serial(refATag){
    var sHolder;
    var maj_asm_serial_nbr;
    sHolder = refATag.refTextBox;
    alert(sHolder);
    maj_asm_serial_nbr = document.all(sHolder).value;
    alert(refATag.id);
    alert(maj_asm_serial_nbr)

    the function for refATag is the same as setting ther variable sHolder

    refTextBox is set in the a href link and in the alert refATag.id, id is in the text field.
    All this is undefined. I still don't see why. all the previous post show the code and this is the function above.
    Also I am using the web to view this so it will display if the code is correct.
    If you see anything wrong, let me know.
    Also I could attatch the full page with all the info but that may be a little confusion so that is why I have not attatched it yet.

    Thanks for the help on this monday morning

    dan

  23. #23
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting!!! I see the problem. I was testing this:

    <a href="#" onClick="insertCode(this)">test</a>

    which works. But when I tested this:


    <a href="javascript: insertCode(this)">test</a>

    it doesn't work. Interesting....it won't let us pass the reference this way. Try this :


    <a id="#loopcounter#" style="color: blue; cursor: hand; text-decoration: underline;" onClick="insertCode(this)" refTextBox="maj_asm_serial_nbr#loopcounter#"> Generate UR#loopcounter#</a>

  24. #24
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Northern Virginia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you added the onclick instead of href?
    I added the code and I got an object expected error...I am trying to debug it but not sure what may be missing. you may not be able to get that error since you may not be able to recreate the error. I will continue to try to debug. I hope this will work.

    dan

  25. #25
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, the reason you got the object expected error was because my test function is named insertCode(). Change this to the name of your function check_serial() and it should work.

    <a id="#loopcounter#" style="color: blue; cursor: hand; text-decoration: underline;" onClick="check_serial(this)" refTextBox="maj_asm_serial_nbr#loopcounter#"> Generate UR#loopcounter#</a>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •