openSUSE Forums > Programming/Scripting » Need help with html / php / javascript

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-Oct-2009, 20:20
Knurpht's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: groningen, netherlands
Posts: 1,790
Knurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enough
Default Need help with html / php / javascript

Hi, I'm working on an open source project for some non-profit organisations. I'm want to change this line:

Code:
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $_SERVER['PHP_SELF'] ?>?option=XXXXXXX&page=XXXXXXX&product_id='+document.getElementById('product_id').options[selectedIndex].value; ">
to a line that does not only take the &product_id value, read from a dropdown selection menu, but also the &order_id="$order_id"&user_id="$user_id"

I've tried many options, but somehow I'm not using the right quotes at the right moment.

Hope this is enough to see what I mean.
__________________
- AMD Athlon X2 6.0 GHz, 8 GB DDR2-800, 30 GB SSD, 1.5 TB, EVGA 9800GT, openSUSE 11.2 KDE4 4.3.3
- ASUS K70IO laptop, GT120M-1GB, 4 GB, 64 GB SSD, opensuse Factory, KDE4 4.3.3

R.E.S.T.E.C.P.
Reply With Quote
  #2 (permalink)  
Old 05-Oct-2009, 04:35
weighty_foe's Avatar
Student Penguin
 
Join Date: Sep 2008
Location: Earl Shilton UK
Posts: 99
weighty_foe hasn't been rated much yet
Default Re: Need help with html / php / javascript

Try:

Quote:
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $_SERVER['PHP_SELF'] ?>?option=XXXXXXX&page=XXXXXXX&order_id=<?php echo $order_id; ?>&user_id=<?php echo $user_id; ?>&product_id='+document.getElementById('product_i d').options[selectedIndex].value; ">
Have you thought of using some kind of javascript framework like jQuery (my fave)?
__________________
Happily using Linux since 1998
Share & Enjoy
Reply With Quote
  #3 (permalink)  
Old 05-Oct-2009, 04:47
weighty_foe's Avatar
Student Penguin
 
Join Date: Sep 2008
Location: Earl Shilton UK
Posts: 99
weighty_foe hasn't been rated much yet
Default Re: Need help with html / php / javascript

Left it too long to edit

This is neater (using a function):
Quote:
<select class="inputbox" id="product_id" name="product_id"

onchange="buildUrl(document.getElementById('produc t_id').options[selectedIndex].value);">
<option value="1">1</option>
<option value="2">2</option>
<option value="4">4</option>
</select>


<script type="text/javascript">
function buildUrl(prodid) {
url="foo.html?option=XXXXXXX&page=XXXXXXX";
url+="&product_id="+prodid;
url+="&user_id=foo&order_id=bar";

window.location=url;


}

</script>
Obviously, I called my page foo.html, not having a php environment on me...
__________________
Happily using Linux since 1998
Share & Enjoy
Reply With Quote
  #4 (permalink)  
Old 05-Oct-2009, 07:47
Knurpht's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: groningen, netherlands
Posts: 1,790
Knurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enough
Default Re: Need help with html / php / javascript

Thank you so very much.....I'm not at my machine now, but will try tonight and post results. Same for second solution, which is more elegant IMHO.

Thanks again,

Gertjan
__________________
- AMD Athlon X2 6.0 GHz, 8 GB DDR2-800, 30 GB SSD, 1.5 TB, EVGA 9800GT, openSUSE 11.2 KDE4 4.3.3
- ASUS K70IO laptop, GT120M-1GB, 4 GB, 64 GB SSD, opensuse Factory, KDE4 4.3.3

R.E.S.T.E.C.P.
Reply With Quote
  #5 (permalink)  
Old 05-Oct-2009, 08:47
Knurpht's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: groningen, netherlands
Posts: 1,790
Knurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enough
Default Re: Need help with html / php / javascript

The first one:

Code:
<select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $_SERVER['PHP_SELF'] ?>?option=XXXXXXX&page=XXXXXXX&order_id=<?php echo $order_id; ?>&user_id=<?php echo $user_id; ?>&product_id='+document.getElementById('product_i d').options[selectedIndex].value; ">
does not work. It does not complain, the values are not used. Changed via ssh and vi, will change other solution tonight.

Thanks anyway
__________________
- AMD Athlon X2 6.0 GHz, 8 GB DDR2-800, 30 GB SSD, 1.5 TB, EVGA 9800GT, openSUSE 11.2 KDE4 4.3.3
- ASUS K70IO laptop, GT120M-1GB, 4 GB, 64 GB SSD, opensuse Factory, KDE4 4.3.3

R.E.S.T.E.C.P.
Reply With Quote
  #6 (permalink)  
Old 05-Oct-2009, 10:00
Knurpht's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: groningen, netherlands
Posts: 1,790
Knurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enough
Default Re: Need help with html / php / javascript

Cheers again !!! Got it solved. Both didn't work, there's definitely something wrong in the single or double quotes. This does the job:
Code:
	      <?php
	      $url = $_SERVER['PHP_SELF']."?option=XXXXXXX&page=XXXXXXX&order_id=". $order_id . "&user_id=" . $user_id ; 
	      ?>
	      <select class="inputbox" id="product_id" name="product_id" onchange="window.location='<?php echo $url ?>&product_id='+document.getElementById('product_id').options[selectedIndex].value;   ">
I can't realy see the difference, but it's working now !!! I recognized the second way to work it out, and remembered I had about the same problem in the beginning of this project, late last year. Quite elegant as well IMHO.
__________________
- AMD Athlon X2 6.0 GHz, 8 GB DDR2-800, 30 GB SSD, 1.5 TB, EVGA 9800GT, openSUSE 11.2 KDE4 4.3.3
- ASUS K70IO laptop, GT120M-1GB, 4 GB, 64 GB SSD, opensuse Factory, KDE4 4.3.3

R.E.S.T.E.C.P.
Reply With Quote
  #7 (permalink)  
Old 06-Oct-2009, 03:00
weighty_foe's Avatar
Student Penguin
 
Join Date: Sep 2008
Location: Earl Shilton UK
Posts: 99
weighty_foe hasn't been rated much yet
Default Re: Need help with html / php / javascript

Glad you got it fixed

I think the quotes problem might be because I didn't check actually echo'ing out the values - missed a trick there...

I like the web developer toolbar for firefox. It's got a nice javascript debugger in it which helps with things like that. Worth getting that & firebug if you're doing much web work.
__________________
Happily using Linux since 1998
Share & Enjoy
Reply With Quote
  #8 (permalink)  
Old 07-Oct-2009, 02:46
Knurpht's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: groningen, netherlands
Posts: 1,790
Knurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enoughKnurpht 's reputation will be famous soon enough
Default Re: Need help with html / php / javascript

Thanks. I'll have a look at those. And
Quote:
if you do much webwork
: this is what I'm working on, I consider it as quite a lot:

This one counts the lines for all modules on my project:

find /srv/www/htdocs -iname '*.*_*.*' | xargs -n 1 wc -l | cut -d' ' -f1 | (SUM=0; while read NUM; do SUM=$(($SUM+$NUM)); done; echo $SUM)

It outputs: 843658

Considering the trouble the post was about: I forgot a very important guideline some php programmer gave me before I started the project: "In case of confusion caused by mixture of php-, html- and javascript statements and their use of quotes, pack them all into to single php-statements and glue those together". In the end, that's what I did.
__________________
- AMD Athlon X2 6.0 GHz, 8 GB DDR2-800, 30 GB SSD, 1.5 TB, EVGA 9800GT, openSUSE 11.2 KDE4 4.3.3
- ASUS K70IO laptop, GT120M-1GB, 4 GB, 64 GB SSD, opensuse Factory, KDE4 4.3.3

R.E.S.T.E.C.P.
Reply With Quote
  #9 (permalink)  
Old 07-Oct-2009, 06:34
weighty_foe's Avatar
Student Penguin
 
Join Date: Sep 2008
Location: Earl Shilton UK
Posts: 99
weighty_foe hasn't been rated much yet
Default Re: Need help with html / php / javascript

Man alive.

That's a lot of code I do smallish websites for fun and occasionally profit.

I will bow down to your greater linecount though
__________________
Happily using Linux since 1998
Share & Enjoy
Reply With Quote
  #10 (permalink)  
Old 05-Nov-2009, 20:04
Explorer Penguin
 
Join Date: Sep 2008
Posts: 161
dmera hasn't been rated much yet
Default Re: Need help with html / php / javascript

Hi Knurpht,
I liked your counting command and I wanted to improve it a bit as I didn't like the loop and there is one less filtering now. I think it will be a bit faster(only you can verify that)

find /srv/www/htdocs -iname '*.*_*.*' | xargs -n 1 wc -l | awk '{SUM=SUM+$1} END {print SUM}'
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2