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
- - - - -

Getting Drop Down Values In The Form


  • Please log in to reply
10 replies to this topic

#1 seo_bright

seo_bright

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 292 posts

Posted 12 August 2008 - 04:45 AM

I am working on a feedback page for a client. In that one, we have a drop down text field and containing 4 options. Suppose the customer types in a field wrongly, the fields before that have to appear the same as they where previously entered. While we are able to fetch text values we are having problems with accessing the values for the drop down box. Also the comments which are given in Text Area also is not displaying. Does anyone have an idea on this. I have searched a lot on this topic but could not find a result to this.

#2 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 12 August 2008 - 05:29 AM

I don't understand your question.

How are you trying to access the data? Javascript perhaps? , is it a problem server side, is it the way you are merging data to a template.

Are you using the GET method on the form?

Is the data missing when emailed to you.

Need much more info on what your are actually doing, how you are trying to do it and what the end results you are looking for.

Sorry, couldn't help at this stage.



#3 seo_bright

seo_bright

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 292 posts

Posted 12 August 2008 - 06:47 AM

I am sorry you could not understand. Actually I am trying to validate a feedback form. There are text boxes, then <textarea>, then drop down menu <select>. Only after all values are correct and validated it gets submitted. We have used the same asp page for postabacking also. Suppose a user misses the email id text box, and clicks submit button a message to enter the values should come. Along with that whatever the user had typed earlier should also get displayed in the respective text boxes. We are able to retrieve and display the text box values in the postback form, but we are unable to get the drop down value and textarea values from the form. But when submit button is clicked it loads with default values as like a fresh form with no values in text area and default selection for drop down menu. But client wants to display those values that are already entered before when the form was reloaded during validation. Hope you get my point.



#4 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 12 August 2008 - 07:10 AM

can you give a URL so i can look at the code?

I assume you have given the textarea a name as well as the select list, and you correctly capture the data and re-display it with the form.

Don't forget text area 'value' attribute is not the place to put the entered data, you need to place the entered data between the textarea open and close tag

#5 seo_bright

seo_bright

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 292 posts

Posted 12 August 2008 - 08:22 AM

Thank you 1dmf that idea worked. I tried putting it in a value tag. Similarly how to get values from drop down. Is there any easy way without use of sessions and all. I have kept a value attribute for each drop down but how to assign them in the same form. Any ideas plz. I am searching for a clue in other forums there is just no response even if it is prog forum.












#6 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 12 August 2008 - 08:58 AM

how are you capturing the data? is the form a GET method? javascript? serverside.

what program are you using / language to capture the submitted form data?

on the server side if you are capturing the data in the standard POST data buffer in value pairs, but then want to redisplay the form and highlight the selected option that becomes a lot harder.

You can do it in a number of ways, I use a templating system with PERL as my backend/serverside CGI language, it's very powerful and enables you to do very easiliy what you want as well as enabling code/content separation, as CSS does for HTML.

Firstly I grab the content for the seledt list from a DB or CSV string...
CODE
# constant which holds select list options
use constant LOAN_TYPE => "Secured,Unsecured,Bridging";

#split out into array
my @loan_type = split(/,/,LOAN_TYPE);

#loop array

for(@loan_type){
    # turn into hash
    $_ = {'Loan Type' => $_};

   #compare with form data
    if($_->{'Loan Type'} eq $cgi->param('loan_type')){

        # if match add selected HTML code to hash
        $_->{'sel'} = " selected=\"selected\" ";
    }
}

# output array of hashes to form

$template->param( 'loan_type' => \@loan_type );


ok don't bog yourself down with the code , but I hope you get the idea you need to process the list, work out what was selected, mark that option then in the actual HTML template..

CODE
    <select id="loantype" name="loantype" onchange="check_loan_type(this)";>
    <option value="">Please Select</option>
    <!--tmpl_loop name='loan_type'-->
    <option value="<tmpl_var name='Loan Type'>" <tmpl_var name='sel'> ><!--tmpl_var name='Loan Type'--></option>
    <!--/tmpl_loop-->                                
    </select>


this can be tedious and long winded, but when you get your head round it it's easy and very powerful.

The other way of course is to use Javascript, this does mean JS must be enabled or a browser with JS capabilities, so it's up to you, but if you know what option is selected you can use JS to select the option again..

CODE
// Get Query String
function Querystring_get(key, default_) {

    if (default_ == null) default_ = null;
    
    var value=this.params[key]
    if (value==null) value=default_;
    
    return value
}


// set advice request prodcut enquiry
function getProduct() {
    var qs = new Querystring()
    var rq = qs.get("RQ", "")
    var sel = document.getElementById('reason');
    sel.disabled = false;    
        for(i=1;i<sel.length; i++){
            if(sel.options[i].value == rq){
                sel.options[i].selected = true;
                sel.disabled = true;
            }
        }      
    
}


I use this to get the value from the querystring, loop the 'reason' select list on the form and select the option which matches the query string value.

hope this makes sense

Edited by 1dmf, 12 August 2008 - 09:11 AM.


#7 seo_bright

seo_bright

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 292 posts

Posted 12 August 2008 - 09:07 AM

Sorry to tell you regarding the language. I use Javascript and ASP alone. I am unable to do so using the following:

in asp coding

Client=request("text1")

<td><select name="text1" class="form" id="text1">
<option value="P" <% if "P"=Client then response.write "selected"%>>Products</option>
<option value="S" <% if "S"=Client then response.write "selected"%>>Service</option>
<option value="D" <% if "D"=Client then response.write "selected"%>>Distributor</option>
<option value="C" <% if "C"=Client then response.write "selected"%>>Customer</option>

</select></td>

#8 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 12 August 2008 - 09:19 AM

the correct html is
CODE
selected="selected"
but that's semantics, what you have should work although in ASP , do you use single equals? if i'm comparing in JS or PERL I use
CODE
if var == 'value'
I guess ASP is like VBA anyways, youre using the right concept, so it must be an ASP syntax issue, and ASP isn't realy my bag.

I'll have a quick search after my meeting, but I think someone with ASP skills needs to help



#9 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 12 August 2008 - 10:03 AM

Well looking at other code they have something like this..

CODE
<% if "P"=Request.Form.Item("text1")  then response.write "selected"%>
any help?

you might also need to trim the var...
CODE
Client=Request.Form.Item("text1")
<option value="P" <% if trim(Client) = "P" then response.write "selected"%>>Products</option>



#10 seo_bright

seo_bright

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 292 posts

Posted 13 August 2008 - 02:19 AM

Thanks 1dmf. You gave me a good idea, I worked on it and was able to fetch the selected value. Thanks for your effort in giving the clues for the code. You have really driven me in the right direction.

#11 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,154 posts
  • Location:Worthing - England

Posted 13 August 2008 - 03:29 AM

no probs, sorry we went round the houses, i have only dabled in a tiny bit of ASP when the occasion called for it, so definately a cases of the blind leading the blind on this one lol.gif

Glad you could work it out smile.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users