tinfanide Posted October 29, 2011 Share Posted October 29, 2011 <option value="var1" <?php if($var=="this.value"){echo "SELECTED";} ?> >var 1</option> <option value="var2" <?php if($var=="this.value"){echo "SELECTED";} ?> >var 2</option> I know we can refer to the object's value by using "this".But is there an equivalent word in PHP? Link to comment Share on other sites More sharing options...
Ingolme Posted October 29, 2011 Share Posted October 29, 2011 PHP only runs before the page has loaded. You can send form data to PHP and access it though $_POST or $_GET Link to comment Share on other sites More sharing options...
Don E Posted October 29, 2011 Share Posted October 29, 2011 There is a 'this' in PHP but only really used in classes. ie. $this->firstName = $name; Link to comment Share on other sites More sharing options...
tinfanide Posted October 30, 2011 Author Share Posted October 30, 2011 So I cannot refer to the object in HTML like Javascript does? <option value="ABC" <?php this.value ?> ></option> Any alternative in PHP for this function? Link to comment Share on other sites More sharing options...
Ingolme Posted October 30, 2011 Share Posted October 30, 2011 No. To PHP, the "<option>" is just pure text, the PHP engine doesn't parse the HTML or work with the DOM in any way before sending the content to the client. If you want the value, then just use the value: <option value="var1" <?php if($var=="var1"){echo "SELECTED";} ?> >var 1</option><option value="var2" <?php if($var=="var2"){echo "SELECTED";} ?> >var 2</option> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.