SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pass value to externel js file..

    Ok before i start i better hold my hand up and say i am total useless at javascript. So if this question turns out to have a very easy answer (which i think it might) then i do apologise. I have tried to look for the best solution to my question but i am not even sure what i am looking for.. so here goes..

    I have a small text input area where people can enter a postcode, with this i have two submit buttons, each do different things when clicked. Take a look..

    HTML Code:
    Postcode: <input type="text" id="postcode" size="10" /><br />
    	<input type="submit" value="Place Marker" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint)" /><br />
    	<input type="submit" value="Center Map" onclick="javascript:usePointFromPostcode(document.getElementById('postcode').value, setCenterToPoint)" />
    Ok, now what i want to do is basically do away with all this. So what i intend to do is put the postcode in myself with php echo. And hide it away. So the top line will now look like this...

    HTML Code:
    Postcode: <input type="hidden" id="postcode" value="<?php echo $postcode; ?>" />
    Now, this is where i need help. What i would like to make happen is submit both on the javascript onclick functions as a user enters the page, therefore send the postcode (which has been automatically put in when the user entered the page) automatically over to the external javascript file i have.

    So basically when a user enters the page the postcode will be in place and both javascript functions will be activated automatically.

    I hope i made this clear. i am a total fool at Javascript.

    thanks for any replies or help this may attract.

    Thanks

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the easiest way is to use the onload event

    Code:
    <script type="text/javascript">
    function go() {
        usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint);
        usePointFromPostcode(document.getElementById('postcode').value, setCenterToPoint);
    }
    </script>
    </head>
    <body onload="go()">


  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for response gRoberts.

    You put me in the right direction and with a bit of playing about i got it sorted.

    Thanks again.



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
  •