On Tue, 2010-02-02 at 11:29 -0800, Ryan S wrote:

> Hey!
> i'm just starting with PHP's DOM-XML and need a little help please.
> 
> 
> Basically, first i am trying to see if a input like a textbox has a 'VALUE=' 
> associated with it, if yes, i leave it be, if no, i add a default value.
> 
> This *is working* as can be seen by the attached code below.
> 
> But a bit confused as to how to do the same for a textarea as textarea's do 
> not have a 'VALUE=' attribute.
> 
> Heres my code:
> 
> 
> $website_data = file_get_contents('dom_test.html');//load the website data,
> 
> $dom = new DomDocument; //make a new DOM container in PHP
> $dom->loadHTML($website_data);  //load all the fetched data into the DOM 
> container
> 
> $inputs = $dom->getElementsByTagName('input'); // Find Sections 
> 
> foreach ($inputs as $input) { //***  this block has the guts of the 
> functionality ***
>         if(!$input->getAttribute("value") || 
> $input->getAttribute("value")=="") {
>                 $input->setAttribute("value", "RRRRRRR");
>         }
> }
> 
> 
> 
> // ***** now we come to the textarea bit that is not working *****
> 
> $inputs2 = $dom->getElementsByTagName('textarea'); // Find textareas 
> 
> foreach ($inputs2 as $input2) {
>         if(!$input2->firstChild.nodeValue=="") {
>                 $input2->firstChild.nodeValue=="it works!";
>         }
> }
> 
> 
> 
> echo $dom->saveHTML();
> ?>
> 
> +++++++++++++++++++++++++++++++
> 
> // I have even tried this instead of the above:
> 
> foreach ($inputs2 as $input2) {
>         if(!$input2->getAttribute("defaultValue")=="") {
>                 $input2->setAttribute("defaultValue","it works!");
>         }
> }
> 
> but no joy.
> 
> I'm betting its pretty simple but i dont have a "DOM chart" for php, the only 
> ones i have been able to find via google are for javascript like this one: 
> http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php
> 
> 
> and that chart does not help much.  Does anyone have a PHP DOM chart or a 
> resource that i can use to get started using this?
> 
> Thanks in advance!
> Ryan
> 
> 
> 
>  ------
> - The faulty interface lies between the chair and the keyboard.
> - Creativity is great, but plagiarism is faster!
> - Smile, everyone loves a moron. :-)
> 
> 
> 
>       
> 


When I get stuck on things like this, I find print_r() invaluable as it
can basically dump out the objects entire contents, so I can see what
values it has set.

Thanks,
Ash
http://www.ashleysheridan.co.uk


Reply via email to