[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

echo "<select name='FreeWebsite' value='supp'>";

Posted on 2005-04-16
5
Medium Priority
?
249 Views
Last Modified: 2008-03-06
whjat is the value use for  I use select name as areference to sent to database but  what is value use for
0
Comment
Question by:teera
5 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13797209
Thats an invalid syntax. There is NO "value" attibribute for "select". Value is taken only from their options!
0
 
LVL 6

Assisted Solution

by:alextr2003fr
alextr2003fr earned 700 total points
ID: 13797254
maybe this example will help you :

<?php
  if (isset($_POST['CardType'])) {
          echo 'selected value = '.$_POST['CardType'].'<br>';
  }
?>
  <form name="frm" action="" method="post">
  Card type:
  <select name="CardType">
  <option value="1">Mastercard</option>
  <option value="2">Visa</option>
  <option value="3">Amex</option>
  <option value="4">Diners</option>
  <option value="5">Discover</option>
  <option value="6">JCB</option>
  </select>
  <input type="submit" name="submit" value="Select">
  </form>
0
 

Author Comment

by:teera
ID: 13797288
Hi  ldbkutty
Please explain more I try with the code above when i change value="Select"  to  value="test" the bottom is change the name
to test  but i not understand cleary  ldbkutty  suggestion
Thank you
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13797294
I meant this line is invalid:

echo "<select name='FreeWebsite' value='supp'>";

It should be:

echo "<select name='FreeWebsite'>";

// Can you explain what you are trying to do with: value='supp' ?
0
 
LVL 7

Accepted Solution

by:
lexlythius earned 700 total points
ID: 13799227
As was said above, the value of a SELECT element cannot be set through an HTML attribute (... value="yourvalue"), but it is assigned according to what option the selected instead. It can be retrieved, though, so you can check what is about to be sent through your form (i.e. for validation purposes).

I modified alextr2003fr's script a bit to let you see how it works:

<?php
  if (isset($_POST['CardType'])) {
        echo 'selected value = '.$_POST['CardType'].'<br>';
  }
?>
<form name="frm" action="" method="get">
Card type:
<select name="CardType" value="TRYING_TO_FORCE_SELECT_VALUE">
  <option value="1">Mastercard</option>
  <option value="2">Visa</option>
  <option value="3">Amex</option>
  <option value="4">Diners</option>
  <option value="5">Discover</option>
  <option value="6">JCB</option>
</select>
<button type="button" onClick="alert(document.forms['frm'].CardType.value);">Show my value</button>
<input type="submit" name="submit" value="Select">
</form>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question