SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple form question

    What is the best way to make a form with button out of this:

    <A href="javascript:SomeFunction('open','Some Directory/someprogram.exe');">

    I tried replacing the action contents with the href contents, but all the form did was reload itself. Thanks in advance.
    - Mike
    http://www.georgiaoffroad.com

  2. #2
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, you need to be more specific. If you just want a form that has a button, and that button starts your javascript, then you want something like this:

    <A href="javascript:SomeFunction('open','Some Directory/someprogram.exe');">

    * somefunction() is a function in someprogram *

    <html>
    <head>
    <script language="javascript"
    src= 'SomeDirectory/someprogram.exe' >
    </script>
    </head>

    <body>
    <form>
    <input type="button" onClick = "somefunction();">
    </form>
    </body>
    </html>

    try that, and see if it does the trick. If not, leave a more specific question and I'll do my best to anser it.

    Good luck.

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  3. #3
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't forget that the <A href=... gets left outof the top
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  4. #4
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your best bet is to start using event handlers. I realize a lot of people use href like an actual event handler but really it isn't meant to be.

    <a href="javascript:void(0)" onclick="somefunction('blah','blah2')">link</a>

    I find a lot of people have problems at times with the href method. I have never had a problem with this method. Also the function is the hidden and can't be viewed within the status bar.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'll see if I can be a little more specific ...

    What is the best way to make a form out of this:

    <A href="javascript:SomeFunction('open','somedirectory/someprogram.exe');">

    The basic form would be along the lines of:

    <form action="somepage.html" method="post">
    <input type="submit" value"Install">
    </form>

    I'm just not sure how or where to put the javascript call. I've tried placing it as an onsubmit="javascript:SomeFunction('open','somedirectory/someprogram.exe')" in the <input type=submit>, but that had no effect (page reloaded, no errors).

    I know about adding this to the form tag: onsubmit="return Function(this)" but again I get no effect when I try adding the example code (page reloaded, no errors).

    I'd like to be able to make SomeFunction a script that will run this: ('open','somedirectory/someprogram.exe')

    I suspect this is exceedingly easy and I'm simply overlooking something so early in the morning. Thanks for your help. I'll explain further if needed.
    - Mike
    http://www.georgiaoffroad.com

  6. #6
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "I know about adding this to the form tag: onsubmit="return Function(this)" but again I get no effect when I try adding the example code (page reloaded, no errors). "

    Ok, try putting the onsubmit in the Iput tag instead, after the value for submit. that might do it.

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Maelstrom suggested using an event handler; I'm suggesting revamping your concepts of forms -- or explaining further....

    1) do not use a "type='submit'" button if you are not submitting. Submissions should be used for cgi/server needs; not for local submissions
    2) why do you have an action and a method if you do not wish to post anything?
    3) why do you have 'someprogram.exe'? Is this being executed from a CD, the desktop, or the web?

    <form name='myform'>
    <input type='button' value='Install' onClick = "SomeFunction('open','somedirectory/someprogram.exe')">
    </form>

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Habit. Never used a form when not sending data.

    I'm giving your example a go right now....



    No dice. It is doing the same thing as my first example, which is the page reloads without any other things happening (a setup program is supposed to launch).

    I have the <A href="javascript:SomeFunction('open','somedirectory/someprogram.exe');"> link right below both of our form examples, and it works perfectly (calls someprogram.exe and reloads the page).

    It seems like we should be able to get a form to do the same thing as the link.
    - Mike
    http://www.georgiaoffroad.com

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know if I could translate the little snippet of javascript in the href tag into a function at the top of the page, I wonder if I could get it working.

    Like I said I can get a function call using OnSubmit in the form tag. I just don't know how to pass along my commands from the form tag to function, and make the function "open" or "navigate" or do some other action to the arguement "setup.exe" "index.html" ect.

    I tried making a javascript function with this:

    somefunction {
    open('somedirectory/someprogram.exe');
    }

    However I'm running up agains the same problem again - page reloads without someprogram.exe running. Again the a href link -does- run someprogram.exe.

    Ideas?
    - Mike
    http://www.georgiaoffroad.com

  10. #10
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright. Here's the javascript snippet I've been referring to.

    Code:
    <SCRIPT language=JavaScript>
    function Form1_Validator001(theForm) {
    
    	// Test PW for validity.
        pw = new String(theForm.pw.value);
        if(pw == "") {
    		alert("Please enter the password");
    		return (false);
        }
    
        if(pw == "aeiou") {
    		// pw ok, do stuff
    
    		alert("about to do the open line");
    		open("ReferenceGuide/ReferenceGuide.exe");
    		alert("i just called the open line... and will now continue...");
    		return (true);
    
        } else {
    		alert("Incorrect password.");
    		return (false);
    	}
    
    }
    </script>
    When the correct pw is entered I am prompted to save or open the setup.exe file.

    The href="javascript'open','somedirectory/setup.exe');" bit will run the file without prompt.

    This is boggling.

    How on earth can I get a function to do the same thing that the href tag is doing?
    Last edited by mstembri; Jan 23, 2002 at 17:44.
    - Mike
    http://www.georgiaoffroad.com

  11. #11
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if that is the 'somefunction' you are calling, I have to presume you are cannabilizing code from somewhere. The reasons I say this:

    1) why are sending 2 values ('open','somedirectory/setup.exe') when the function is asking for 1 (theForm)?
    2) where is the HTML form?
    3) what does the href have to do with this?
    4) where is the original button, href, etc?

    your html should look like this:
    <form...>
    <input type='text' name='pw'>
    <a href="#" onClick="Form1_Validator001(this.form)">Enter</a>
    </form>

    or, if you want to substitue a button for the href:
    <input type='button' value='Enter' onClick="Form1_Validator001(this.form)">

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  12. #12
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no conspiracy here. I have a licensed version of Automenu22 (www.touch22.com). Their help file explains how to alter their example autorun menu, which is exactly what is occuring

    Still looking for an answer on how to do the "open", "somedirectory/someprogram.exe" bit in a function as opposed to a href link.

    It all boils down to two things.

    1) I would much prefer having form buttons than text links - it looks better and I have easier control over color/text/size. Yes I could create images and use them in the href tags and get the same sort of effect. I am holding off on doing that until someone proves to me that there is not a way to pull off what I'm trying to do.

    2) It seems that if the href technique works, that I should also be able to get the same result with a function called by a form(button). That would only be logical.

    Thanks for inquiring. And for helping further if you are able.
    - Mike
    http://www.georgiaoffroad.com

  13. #13
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mike,

    If the previous suggestions did not work, you are going to have post a url where the code resides

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •