473,698 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add & delete drop-downs

Hi there,

i have a soccer-site, on which of course,
can be kept track of played matches.
Now the admin has to be able to set the number
of goals, and then select who scored what goal.

I want a system where one can put a number in
a textfield (NaN would return an error).
Say the admin enters '3'. Then three dropdown
lists appear below that field, in them are the
players.
If he turns '3' (goals) into '2', the lowest one
has to be deleted, but the upper two have to stay,
with an unchanged (already selected) value ...

Preferrably cross browser. I just can't seem to
figure out, i've tried loads of innerHTML and
document.write( ), both didn't give me what i
wanted (yet).

Hope someone can help!

Greetings frizzle.

Sep 6 '05 #1
4 1670
frizzle wrote:
Hi there,

i have a soccer-site, on which of course,
can be kept track of played matches.
Now the admin has to be able to set the number
of goals, and then select who scored what goal.

I want a system where one can put a number in
a textfield (NaN would return an error).
Say the admin enters '3'. Then three dropdown
lists appear below that field, in them are the
players.
If he turns '3' (goals) into '2', the lowest one
has to be deleted, but the upper two have to stay,
with an unchanged (already selected) value ...

Preferrably cross browser. I just can't seem to
figure out, i've tried loads of innerHTML and
document.write( ), both didn't give me what i
wanted (yet).


Because they are completely the wrong things to be using.

I think you are better off to have the admin select the player, enter
the number of goals, then add that to some list.

The following example just checks that the number of goals is an
integer, that's all. For general web use, it should also:

- check to see if the same player is added more than once
- not let the user manually modify the results
- provide a way of removing or editing entries

But since it's just an example to get you going...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Goal scorers</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript">
function addToResults( f ){
var g = f.goals.value;
// validate that g is an integer
if ( /^\d+$/.test(g) ) {
f.scorerAndGoal s.value +=
f.players[f.players.selec tedIndex].text +
', ' + g + '\n';
} else {
alert ('Number of goals must be a number, e.g. 2');
}
}
</script>

</head>
<body>
<form name="demoform" action="">
<table>
<tr>
<th>Select a player</th>
<th>How many goals?</th>
<th>Click to add</th>
<th>Scorer and goals</th>
</tr>
<tr>
<td>
<select id="players">
<option>Pelle
<option>Maradon na
<option>Beckh am
</select>
</td>
<td>
<input type="text" id="goals">
</td>
<td align="center">
<input type="button" value="Add to results" onclick="
addToResults(th is.form);
"><br>
<input type="reset" value="Clear form">
</td>
<td>
<textarea id="scorerAndGo als"></textarea>
</td>
</tr>
</table>
</form>

</body>
</html>


--
Rob
Sep 7 '05 #2
Thanks for the reply,
i tried it, but this isn't completely what
i mean ... :-(

What i meant was

********* U G L Y V I S U A L M O D E *********

txt_field goals: [___________2] // should be an integer, e.g. 2

dropdown players:
goal 1: [Pele_______V]

goal 2: [Pele_______V]
|Maradonna |
|Beckham___|

****** / / U G L Y V I S U A L M O D E ******


I want to keep track of who scored what goal. I hope this
is more clear, and not to much to ask ...

Thanks,

Frizzzle.

Sep 7 '05 #3
frizzle wrote:
Thanks for the reply,
i tried it, but this isn't completely what
i mean ... :-(

What i meant was

********* U G L Y V I S U A L M O D E *********

txt_field goals: [___________2] // should be an integer, e.g. 2

dropdown players:
goal 1: [Pele_______V]

goal 2: [Pele_______V]
|Maradonna |
|Beckham___|

****** / / U G L Y V I S U A L M O D E ******


I want to keep track of who scored what goal. I hope this
is more clear, and not to much to ask ...

Thanks,

Frizzzle.


Sorry, I just don't like the 'enter a number' bit. The following uses a
button to add and delete goals. It needs some work to make it suitable
for the web, it's dependent on the page structure and naming
conventions, but it gives you a start:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Goal scorers</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<style type="text/css">
table { border-collapse: collapse;}
td {vertical-align: top;}
select {width: 10em; margin: 5px 0px 0px 5px;}
input {width: 10em;}
..goalCell {
text-align: right;
padding-left: 5px;
border: 1px solid green;
}
</style>

<script type="text/javascript">
// Get the last select element with id containing 'goal-'
// Goes thru elements from last to first, returns first match
function getLastGoal( f )
{
var el, els = f.elements;
var i = els.length;
while ( i-- ){
el = els[i];
if ( el.id && /goal-/.test(el.id) ) {
return el;
}
}
}

// Return the first div that is a parent of el
function getDiv ( el )
{
while ( el.parentNode && 'div' != el.nodeName.toL owerCase() ){
el = el.parentNode;
}
return ('div' == el.nodeName.toL owerCase() )? el : null;
}

function addGoal( f )
{
// Get the last goal select element
var elG = getLastGoal( f );

// Get the parent div and clone the whole div
var elD = getDiv( elG );
if ( !elD ) return; // Didn't find a parent div
var newD = elD.cloneNode(t rue);

// Modify the new select element's id (can't have duplicates)
var newG = newD.getElement sByTagName('sel ect')[0];
var newId = newG.id.split('-');
newId[1] = +newId[1] + 1;
newG.id = newId[0] + '-' + newId[1];

// Modify the text
newD.firstChild .data = 'Goal ' + newId[1];

// Add the new Div
elD.parentNode. appendChild( newD );
}

function delGoal( f )
{
// Get the last goal select element
var elG = getLastGoal( f );

// If it's the last one, don't delete it
if ( 'goal-1' == elG.id ) return;

// Get the parent Div & delete last goal div
var elD = getDiv( elG );
elD.parentNode. removeChild( elD );
}

</script>
</head>
<body>
<form name="goalsScor ed" action="">
<table>
<tr>
<td>
<input type="button" value="Add new goal" onclick="
addGoal( this.form );
"><br>
<input type="button" value="Delete last goal" onclick="
delGoal( this.form );
"><br>
<input type="reset" value="clear form">
<td class="goalCell ">
<div>Goal 1
<select id="goal-1">
<option selected>
<option>Pelle
<option>Maradon na
<option>Beckh am
</select>
</div>
</td>
</tr>
</table>
</form>

</body>
</html>
--
Rob
Sep 7 '05 #4
Wow! Great work!
I only have one but ... :-(
Would'nt this mean there always
has to be at least 1 goal?

Frizzle.

Sep 7 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15463
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that shows all current backups, and restores the selected one with one click...
1
8894
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row. However:
3
1567
by: lreames | last post by:
I am running SQL 2000 SP2 on a Win 2000 box. I attempted to restore a dB a couple of times and the restore failed, but the dB appears in EM twice, once with Loading and the other with Read-Only. I stopped SQL and attempted to delete the LDF & MDF files, but there was a sharing violation. How can I detach these dBs from the SQL server?? Detach is not an option, because the 'OK' button is not clickable. HELP anyone.
3
2208
by: Fred R | last post by:
I'm designing an app in Access 97 that will facilitate the uploading of records and images to a website. The user selects the image thumbnails from the file system and drags them into the app. There appears to be just two types of controls that support this action: OLE controls and Hyperlink text boxes. I am using the hyperlink. Dragging the images into the hyperlink works just fine, but I'm quite dismayed about the lack of control over...
1
2604
by: Mike Chan | last post by:
Is it possible to drop a file from the VB.Net Application to the "Desktop" or somewhere and start the copy file action? (I already know how to drop in the application, but no idea how to drop out)
1
1673
by: Marco Zender | last post by:
Hello, i'm in real trouble and don't know how to handle it! May someone can give me a hint? Following problem: In my application you can drag&drop a file from the explorer. In my application this file will be encrypted and then you should be able to drag&drop the file from the application to the explorer. How can i code the last step ?!? I have tried it with DoDragDrop but without success :-( TIA
5
3805
by: Microsoft | last post by:
Hi, I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems; a.. Under the "Connection" tab, under "1. Select or enter a server name:" when I either select the drop down box or click the refresh button I get an error dialog saying "Error enumerating data servers. Enumerator reports Unspecified error'". The...
1
1437
by: dirk van waes | last post by:
Hello everyone, Being complete newbie in asp.net I am trying to make an example which works with a very simple database. First I made my project in VS- vb.net, draging an oledbconnection and an oledbdataadapter from the toolbox into my form. Everything worked fine on my local computer. I was able to search, update, delete and insert into my klanten.mdb database.
0
2506
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
0
1987
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.