Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!


Sponsored Content

 

 
 

Photo
- - - - -

Inserting A Value Into A Form, Help


  • Please log in to reply
12 replies to this topic

#1 heyman

heyman

    HR 3

  • Active Members
  • PipPipPip
  • 53 posts

Posted 07 December 2004 - 03:08 PM

Inserting a value into a form help



Hello ,

I am looking for a cgi script that will automatically insert a value into a text input field, when a link is clicked

The scenario:

we sell machines, and costumers have the option of requesting a quote, I would like to have the model # of the machine automatically inserted into the quote when the costumer clicks the "request a quote" link.


thanks

#2 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 5,882 posts
  • Location:Blackpool UK

Posted 07 December 2004 - 04:27 PM

The actual how will depend on the server side technology, but all you need to do is to pass the value as a querystring with the link, retrieve it from the request collection and insert it to the form.

#3 heyman

heyman

    HR 3

  • Active Members
  • PipPipPip
  • 53 posts

Posted 08 December 2004 - 11:44 AM

"The actual how will depend on the server side technology"



FreeBSD operating system, version 4.8-STABLE.
Apache is used and has the following modules installed:
mod_env
mod_php
mod_setclass
mod_log_config
mod_mime
mod_negotiation
mod_status
mod_include
mod_autoindex
mod_dir
mod_cgi
mod_asis
mod_imap
mod_actions
mod_userdir
mod_alias
mod_rewrite
mod_access
mod_auth
mod_frontpage
mod_auth_anon
mod_auth_dbm
mod_digest
mod_expires
mod_headers
mod_unique_id
mod_setenvif


Is that what you were looking for?

Links to tutorials or script would also help, thanks.

#4 Renagade Master

Renagade Master

    HR 4

  • Active Members
  • PipPipPipPip
  • 137 posts
  • Location:London, UK

Posted 08 December 2004 - 12:04 PM

I would have a link like this:
CODE
<a href="www.yoursite.com?request_quote.php?model=12345>SOHO Quote</a>


Then the request_quote.php would return a html file with this in it:

CODE
<input type="text" value="12345" name="ref_num" />


Don't know if a script is available for this, but it shouldn't be that difficult with some PHP knowledge or a good book.


HTH - Renegade.

#5 linux_lover

linux_lover

    LiLo

  • Active Members
  • PipPipPipPipPipPip
  • 831 posts
  • Location:York, UK

Posted 08 December 2004 - 01:28 PM

Heres a bit of Javascript code to do what you are asking:

CODE
<form name="myform">
<input type="text" name="moo" />
</form>

<script language="javascript">
function populateField(form, field, str){
 document[form][field].value = str;
}
</script>

<a href="javascript: populateField('myform', 'moo', 'Some value')">Click</a>


Just pass the formname, field, and a string to the populateField function via the a href and jobs a good'n. You could also call the function via the onmouseup event.

You could mix this with PHP to get the variable from the query string or write a bit of JS to parse it... or do it all in PHP even - but then you would have to make the page refresh methinks.

Cheers

LiLo

#6 heyman

heyman

    HR 3

  • Active Members
  • PipPipPip
  • 53 posts

Posted 08 December 2004 - 03:37 PM

Thanks Lilo,

Pardon me if you have already said this but if you wanted to pass the "some value" to a form on a different page of your website, how would you do that ?

#7 linux_lover

linux_lover

    LiLo

  • Active Members
  • PipPipPipPipPipPip
  • 831 posts
  • Location:York, UK

Posted 09 December 2004 - 03:32 AM

That would be what Chris said, use the querystring

www.yourwebsite.com?var=someval&var2=anotherval

You can get the args from the querystring (the variables) by using a function like this:

CODE
function getArgs() {
    var args = new Object;
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for(var i=0; i<pairs.length; ++i) {
 var pos = pairs[i].indexOf('=');
 if(pos == -1) continue;
 var argname = pairs[i].substring(0, pos);
 var value = pairs[i].substring(pos + 1);
 args[argname] = unescape(value);
    }
    return args;
}

//then get the variables like this:

querystring = getArgs();
alert (querystring.var);


Then you would set the form like I said in the last post...

Personally I would use PHP rather than Javascript, but it depends what you have got available on your server - Javascript pretty much everyone can use.

LiLo

#8 Kev

Kev

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 09 December 2004 - 03:52 AM

You've got PHP so you don't need to use Javascript. Client side coding is dodgy at best - what if your user has JS turned off?

Product link:

CODE
<a href="quote_request.php?m=1234" title="Get a quote for Model 1234!">Model 1234</a>


And in quote_request.php:

CODE
<?php
$m = trim($_GET['m']);
?>
<input type ="text" id="m" value="<?php $m; ?>" />


#9 linux_lover

linux_lover

    LiLo

  • Active Members
  • PipPipPipPipPipPip
  • 831 posts
  • Location:York, UK

Posted 09 December 2004 - 03:59 AM

QUOTE
Client side coding is dodgy at best - what if your user has JS turned off?


Couldnt agree more smile.gif Doing multiple variations of code for every browser gets on my nerves too. I didnt read the bit where he said he had php... bad me.

#10 heyman

heyman

    HR 3

  • Active Members
  • PipPipPip
  • 53 posts

Posted 09 December 2004 - 02:33 PM

I've set up the code that Kev posted

but I can't get the "1234" to show up in the text field when I click on the link

what am I doing wrong?

#11 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 10 December 2004 - 08:08 AM

A slight error in the provided code, assuming you're passing the data to a page that is being processed by php.

Instead of this:
CODE
<?php
$m = trim($_GET['m']);
?>
<input type ="text" id="m" value="<?php $m; ?>" />


Try this:
CODE
<?php
$m = trim($_GET['m']);
?>
<input type ="text" id="m" value="<?php echo $m; ?>" />


#12 Kev

Kev

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 10 December 2004 - 08:40 AM

QUOTE(Randy @ Dec 10 2004, 02:08 PM)
A slight error in the provided code, assuming you're passing the data to a page that is being processed by php.

Instead of this:
CODE
<?php
$m = trim($_GET['m']);
?>
<input type ="text" id="m" value="<?php $m; ?>" />


Try this:
CODE
<?php
$m = trim($_GET['m']);
?>
<input type ="text" id="m" value="<?php echo $m; ?>" />

Ouch, good spot Randy. Sorry heyman. Next time I'll actually look at what I'm typing wink.gif

#13 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 10 December 2004 - 09:22 AM

I'm used to troubleshooting my own code Kev. lol.gif

Practice makes perfect they say. Doesn't keep me from mucking things up on a daily (hourly?) basis, but I have gotten much better at spotting stuff. wink.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users